<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysDictDataService;
use app\adminapi\validate\SysDictDataValidate;
use app\common\controller\BaseAdminController;

class SysDictDataController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $param = (new SysDictDataValidate())->get()->goCheck('list');
        $result = (new SysDictDataService())->list($param);

        return app('json')->successWithData($result);
    }

    /**
     * @title   新增字典值
     * @businessType INSERT
     */
    public function insert()
    {
        $param = (new SysDictDataValidate())->post()->goCheck('insert');
        $result = (new SysDictDataService())->addSysDictData($param);
        return app('json')->successWithData($result);
    }

    /**
     * @title 删除字典值
     * @businessType DELETE
     */
    public function delete()
    {
        $param = (new SysDictDataValidate())->delete()->goCheck('delete');
        $result = (new SysDictDataService())->deleteSysDictData($param['dictDataId']);
        return app('json')->successWithData($result);
    }

    /**
     * @title 更新字典值
     * @businessType UPDATE
     */
    public function update()
    {
        $param = (new SysDictDataValidate())->put()->goCheck('update');
        $result = (new SysDictDataService())->updateSysDictData($param);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $param = (new SysDictDataValidate())->get()->goCheck('query');
        $result = (new SysDictDataService())->getSysDictData($param['dictDataId']);
        return app('json')->successWithData($result);
    }

    public function queryByType()
    {
        $param = (new SysDictDataValidate())->get()->goCheck('getDataByType');
        $result = (new SysDictDataService())->listByType($param['dictType']);
        return app('json')->successWithData($result);
    }
}